#include "shimadzufindpacket.h"
#include "misc.h"
#include <QDateTime>

ShimadzuFindPacket::ShimadzuFindPacket(QObject *parent)
    : BaseFindPacket (parent)
{

}

ShimadzuFindPacket::~ShimadzuFindPacket()
{

}

QList<ProtocolPacket> ShimadzuFindPacket::find(const QByteArray &data)
{
    m_rxBuffer.append(data);

    QList<ProtocolPacket>   packets;
    while (!m_rxBuffer.isEmpty())
    {
        char _data = m_rxBuffer.at(0);
        m_rxBuffer.remove(0, 1);//移除头字节

        m_rxPacket.append(_data);

        if (_data == 0x0D) // 帧尾
        {
            if (m_rxPacket.size() >= 13)
            {
                ProtocolPacket packet;
    //            packet.timestamp = Misc::getTimeStamp();
                packet.timestamp = QDateTime::currentMSecsSinceEpoch();
                packet.buffer = m_rxPacket;
                packets << packet;
            }

            m_rxPacket.clear();
        }

    } // while

    return packets;
}
